package com.itheima.stringbuilder;

import java.util.Arrays;

public class TestDemo02 {
    public static void main(String[] args) {
        int[] arr = {1, 2, 3, 4, 5};
        String str = arrayToString(arr);
        System.out.println(str);
        System.out.println(Arrays.toString(arr));
    }

    //定义方法
    public static String arrayToString(int[] arr) {
        StringBuilder sb = new StringBuilder("[");
        for (int i = 0; i < arr.length; i++) {
            if (i != arr.length - 1) {
                sb.append(arr[i]).append(", ");
            } else {
                sb.append(arr[i]).append("]");
            }
        }
        return sb.toString();
    }
}
